import { post, postJson } from './utils';

import axios from 'axios';

export const gethl = (variable = 'hl') => {
  var arrStr = window.location.search.substring(1).split("&");
  for (var i = 0; i < arrStr.length; i++) {
    var temp = arrStr[i].split("=");
    if (temp[0] === variable){
        return decodeURIComponent(temp[1]);
    }    
  }
  return "zh_cn"
}

export function URLP(variable) {
  var arrStr = window.location.search.substring(1).split("&");
  for (var i = 0; i < arrStr.length; i++) {
    var temp = arrStr[i].split("=");
    if (temp[0] === variable){
        return decodeURIComponent(temp[1]);
    }    
  }
  return false
} 

// export const domain = "//10.10.10.1:8080/";
export const domain = "//h5.likehealth.com.cn";

export function OauthBindCode(phone,itac){
  return post(domain+"/api/oauth/bind/code?phone="+phone+"&itac="+itac)
}

export function OauthBindPhone(phone,code,itac){
  return post(domain+"/api/oauth/bind/phone?phone="+phone+"&itac="+itac+"&code="+code)
}

export function FromStaffList(limit,offset){
  return post(domain+"/api/workorder/from/staff/list?limit="+limit+"&offset="+offset)
}

export function MessageHandle(order_no){
  return post(domain+"/api/workorder/message/handle?order_no="+order_no)
}

export function MessageReceive(order_no,limit,offset){
  return post(domain+"/api/workorder/message/receive?order_no="+order_no+"&limit="+limit+"&offset="+offset)
}

export function UseCodeToToken(code){
  return post(domain+"/api/oauth/usecodetotoken?code="+code)
}

export function ResetPassword(phone,pass,itac,code){
  return post(domain+"/api/auth/reset/password?pass="+pass+"&phone="+phone+"&itac="+itac+"&code="+code)
}

export function GetUnderwriterFromInfo(order_no){
  return post(domain+"/api/underwriter/from/info?order_no="+order_no)
}
export function CreateUnderwriterFrom(order_no,data){
  return postJson(domain+"/api/underwriter/from?order_no="+order_no,data)
}
export function UnderwriterCreateOrder(){
  return post(domain+"/api/underwriter/create/order?o=o")
}
export function UnderwriterQueryReceiveFreecount(){
  return post(domain+"/api/underwriter/query/receive/freecount?o=o")
}

export function GetWorkOrderFromInfo(order_no){
  return post(domain+"/api/workorder/from/info?order_no="+order_no)
}
export function CreateWorkOrderFrom(order_no,data){
  return postJson(domain+"/api/workorder/from?order_no="+order_no,data)
}
export function WorkOrderCreateOrder(){
  return post(domain+"/api/workorder/create/order?o=o")
}
export function WorkOrderQueryReceiveFreecount(){
  return post(domain+"/api/workorder/query/receive/freecount?o=o")
}

export function login(phone,pass,itac) {
  return post(domain+"/api/auth/login?pass="+pass+"&phone="+phone+"&itac="+itac)
}
export function StaffLogin(phone,pass,itac) {
  return post(domain+"/api/staff/login?pass="+pass+"&phone="+phone+"&itac="+itac)
}
export function register(phone,pass,itac,code) {
  return post(domain+"/api/auth/register?pass="+pass+"&phone="+phone+"&itac="+itac+"&code="+code)
}
export function getphonecode(phone,itac,type=2) {
  return post(domain+"/api/auth/send/msgcode?phone="+phone+"&itac="+itac+"&type="+type)
  // http://www.likehealth.com.cn/apis/user/code_phone?phone=13064754732&type=1&f=1&kind=1
}
// 不必要的 authtoken
export function oauthlogin(redirect_call) {
  return post(domain+"/api/oauth/wechat?redirect_call="+redirect_call)
}
export function paymember() {
  return post(domain+"/api/member/join/order?product_id=1")
}

export function wxpayjsapi(order_no, notify_url = domain+"/api/member/order/notify") {
  return post(domain+'/api/pay/wechat/jsapi?order_no='+ order_no + '&notify_url='+ notify_url)
}
// orderstatus 支付完成后检查订单状态
export function orderstatus(order_no) {
  return post(domain+'/api/order/status?order_no='+ order_no)
}
export function memberjoincheck(){
  return post(domain+'/api/member/join/check?o=o')
}

export function allorder(){
  return post(domain+'/api/order/all?o=o')
}

export function nopayorder(){
  return post(domain+'/api/order/nopay?o=o')
}

export function okorder(){
  return post(domain+'/api/order/ok?o=o')
}

export function wxjssdk(){
    return post(domain+'/api/sdk/wechat/jssdk?sdk_uri='+encodeURIComponent(window.location.href))
}
export function userinfo(){
  return post(domain+'/api/user/info?o=o')
}
export function deleteorder(order_no){
  return post(domain+'/api/order/delete?order_no='+order_no)
}
export function revokeorder(order_no){
  return post(domain+'/api/order/revoke?order_no='+order_no)
}

export function getEmojiData() {
  return axios({
      method: 'get',
      url: './../static/emojiDB.json',
    })
    .then(function(res) {
      return Promise.resolve(res.data);
    });
}